﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DrugStorehouseMIS.Comm;
using DrugStorehouseMIS.DAL.Interface;


namespace DrugStorehouseMIS.DAL
{
    public class UserDAL:IUserDAL
    {

        #region IUserDAL 成员

        public IDataReader Select(string UserNum)
        {
            try
            {
                return SqlDbHelper.RunProcedure_Reader(ConnectionString.ConnString, "Proc_User_Select", new SqlParameter[] { new SqlParameter("@UserNum", UserNum) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }        
        }

        public int Insert(string UserNum, string UserType,string UserName, string UserPassword, string CreatedBy, string LastUpdatedBy,int FlagDisable)
        {
            try
            {
                SqlParameter[] para = new SqlParameter[]
                {
                    new SqlParameter("@UserCode",UserNum),
                    new SqlParameter("@UserType",UserType),
                    new SqlParameter("@UserName",UserName),
                    new SqlParameter("@UserPassword",UserPassword),
                    new SqlParameter("@CreatedBy",CreatedBy),
                    new SqlParameter("@LastUpdatedBy",LastUpdatedBy),
                    new SqlParameter("@FlagDisable",FlagDisable)
                };
                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_User_Insert", para);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }      
        }

        public int Delete(string UserNum)
        {
            try
            {
                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_User_Delete", new SqlParameter[] { new SqlParameter("@UserCode", UserNum) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public int Update(string UserNum, string UserType, string UserName, string UserPassword, string LastUpdatedBy, int FlagDisable)
        {
            try
            {
                SqlParameter[] para = new SqlParameter[]
                {
                    new SqlParameter("@UserNum",UserNum),
                    new SqlParameter("@UserType",UserType),
                    new SqlParameter("@UserName",UserName),
                    new SqlParameter("@UserPassword",UserPassword),
                    new SqlParameter("@LastUpdatedBy",LastUpdatedBy),
                    new SqlParameter("@FlagDisable",FlagDisable)
                };
                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_User_Update", para);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }           
        }

        #endregion
    }
}
